Solved: Outlook "Check Names" feature in visual basic.net or C# 您所在的位置:网站首页 khalid mehmood awan Solved: Outlook "Check Names" feature in visual basic.net or C#

Solved: Outlook "Check Names" feature in visual basic.net or C#

2023-03-23 17:30| 来源: 网络整理| 查看: 265

One code snippet is attached, the other is here ... This solved my issue.

聽Public Shared Function AuthenticateUserPassword(ByVal szUserName As String, ByVal szPassword As String) As Boolean 聽 聽 聽 聽 Dim result As Boolean = False 聽 聽 聽 聽 Dim szUserDomain As String = "" 聽 聽 聽 聽 Dim myLDAPPath As String

聽 聽 聽 聽 ' Determine what the domain name should be. 聽 聽 聽 聽 If szUserName.Contains("\") Then 聽 聽 聽 聽 聽 聽 ' Pull the domain out of the user name. 聽 聽 聽 聽 聽 聽 szUserDomain = szUserName.Substring(0, szUserName.IndexOf("\")) 聽 聽 聽 聽 聽 聽 ' Set user name to just user name. 聽 聽 聽 聽 聽 聽 szUserName = szUserName.Substring(szUserName.IndexOf("\") + 1) 聽 聽 聽 聽 ElseIf szUserName.Contains("@") Then 聽 聽 聽 聽 聽 聽 ' User Name is in form of "user@domain" 聽 聽 聽 聽 聽 聽 ' Pull the domain out of the user name. 聽 聽 聽 聽 聽 聽 szUserDomain = szUserName.Substring(szUserName.IndexOf("@") + 1) 聽 聽 聽 聽 聽 聽 ' Set user name to just user name. 聽 聽 聽 聽 聽 聽 szUserName = szUserName.Substring(0, szUserName.IndexOf("@")) 聽 聽 聽 聽 Else 聽 聽 聽 聽 聽 聽 ' A "." refers to the local system. 聽 聽 聽 聽 聽 聽 szUserDomain = Environment.MachineName 聽 聽 聽 聽 聽 聽 szUserName = szUserName.Substring(szUserName.IndexOf("\") + 1) 聽 聽 聽 聽 End If

聽 聽 聽 聽 ' Determine which entry it will need to be. 聽 聽 聽 聽 If String.Compare(szUserDomain, Environment.MachineName, True) = 0 Then 聽 聽 聽 聽 聽 聽 myLDAPPath = "WinNT://" &聽szUserDomain 聽 聽 聽 聽 Else 聽 聽 聽 聽 聽 聽 myLDAPPath = "LDAP://" &聽szUserDomain 聽 聽 聽 聽 End If

聽 聽 聽 聽 Try 聽 聽 聽 聽 聽 聽 Dim entry As DirectoryEntry = New DirectoryEntry(myLDAPPath, szUserName, szPassword) 聽 聽 聽 聽 聽 聽 Dim nativeObject As Object = entry.NativeObject 聽 聽 聽 聽 聽 聽 result = True 'no exception thrown, user must exist 聽 聽 聽 聽 聽 聽 nativeObject = Nothing 聽'be sure and clean up these object as this service could be used many times 聽 聽 聽 聽 聽 聽 entry = Nothing 聽 聽 聽 聽 Catch ex As Exception 聽 聽 聽 聽 聽 聽 result = False 聽'exception thrown - no user with that name/pwd combination 聽 聽 聽 聽 End Try 聽 聽 聽 聽 Return result 聽 聽 End Function

Public Shared Function AD(ByVal strQuery As String, ByVal strReturn As String, ByRef listbox1 As ListBox) If strQuery = "" Then Exit Function End If 'strQuery = "[email protected]" Dim oroot As DirectoryServices.DirectoryEntry = New DirectoryServices.DirectoryEntry("LDAP://mobilink") Dim osearcher As DirectoryServices.DirectorySearcher = New DirectoryServices.DirectorySearcher(oroot) Dim result As DirectoryServices.SearchResult Dim resultAll As DirectoryServices.SearchResultCollection 'osearcher.Filter = "(&(objectCategory=person)(objectClass=user)(mail=" & strQuery & "))" ' search filter osearcher.Filter = "(&(anr=" & strQuery & ")(mail=*))" ' search filter resultAll = osearcher.FindAll() If resultAll.Count > 0 Then For i As Integer = 0 To (resultAll.Count - 1) listbox1.Items.Add(resultAll(i).Properties("mail")(0).ToString()) Next End If oroot = Nothing osearcher = Nothing result = Nothing resultAll = Nothing Exit Function End Function

Open in new window



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有